package com.blockchain.wmm.core.service;

import com.blockchain.wmm.block.bean.Instruction;
import com.blockchain.wmm.common.Sha256;
import com.blockchain.wmm.common.TrustSDK;
import com.blockchain.wmm.common.exception.TrustSDKException;
import org.springframework.stereotype.Service;

/**
 * @author wangzun
 * 指令集业务操作类
 * */
@Service
public class InstructionService {

    /**
     * 根据指令内容校验签名是否匹配
     * */
    public boolean checkSign(Instruction instruction) throws TrustSDKException {
        String buildStr = instruction.getOperation() + instruction.getTable() + instruction.getJson();
        return TrustSDK.verifyString(instruction.getPublicKey(),buildStr,instruction.getSign());
    }

    public boolean checkHash(Instruction instruction) {
        String buildStr = instruction.getOperation() +instruction.getTable() + instruction.getJson();
        return Sha256.sha256(buildStr).equals(instruction.getHash());
    }
}
